#include<bits/stdc++.h>
using namespace std;
int n,k,q,a[100005];
void solve(int x,int y) {
	int sum=0;
	for(int i=x; i<=y; i++) {
		int len=n-1,v=a[i],l=i,r=i;
		while(len>0) {
			if(l!=1&&a[l-1]<=v) {
				sum++;
				len--;
				l--;
			} else if(r!=n&&a[r+1]<=v) {
				sum++;
				len--;
				r++;
			} else {
				sum+=k;
				v=min(a[l-1],a[r+1]);
			}
		}
	}
	cout<<sum<<endl;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout);
	cin>>n>>k;
	for(int i=1; i<=n; i++) cin>>a[i];
	cin>>q;
	a[0]=a[n+1]=1e9;
	for(int i=1; i<=q; i++) {
		int x,l,r;
		cin>>x>>l>>r;
		swap(a[x],a[x+1]);
		solve(l,r);
	}
	return 0;
}

